package com.sk.weichat.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.sk.weichat.R;
import com.sk.weichat.util.ScreenUtil;
import com.sk.weichat.util.ToastUtil;

/**
 * @Author: chenzl
 * @ClassName: RedPacketDialog
 * @Description: 红包 弹出支付对话框
 * @CreateDate: 2019/10/9 15:24
 */
public class RedPacketDialog extends Dialog {

    private CheckBox check_alipaly;
    private Button btn_send_redpacket;
    private ImageView img_close;
    private OnSendRedPacketListener mOnSendRedPacketListener;
    private Context context;
    public RedPacketDialog(Context context,OnSendRedPacketListener mOnSendRedPacketListener) {
        super(context, R.style.BottomDialog);
        this.context = context;
        this.mOnSendRedPacketListener = mOnSendRedPacketListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_redpacket);
        Window o = getWindow();
        WindowManager.LayoutParams lp = o.getAttributes();
        lp.width = (int) (ScreenUtil.getScreenWidth(getContext()) * 0.8);
        lp.gravity = Gravity.CENTER;
        o.setAttributes(lp);
        initView();
    }

    private void initView(){
        img_close = findViewById(R.id.img_close);
        img_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        check_alipaly = findViewById(R.id.check_alipaly);
        btn_send_redpacket = findViewById(R.id.btn_send_redpacket);
        btn_send_redpacket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (check_alipaly.isChecked()){
                    dismiss();
                    mOnSendRedPacketListener.senRedPacketClick();
                }else {
                    ToastUtil.showToast(context,"请选择支付方式");
                }
            }
        });
    }

    public interface OnSendRedPacketListener {
        void senRedPacketClick();
    }
}
